﻿using System;
using AutoMapper;
using DDDNorthWind.Core.Domain.ValueObject;

namespace DDDNorthWind.Core.Test.ValueObject
{
    public class Address:ValueObject<Address>
    {
        static Address()
        {
            Mapper.CreateMap<Address, Address>();
        }

        [Obsolete("For Empty in ValueObject comparer")]
        public Address(): this(string.Empty, string.Empty,string.Empty) {}
        

        public Address(string province, string zip, string street)
        {
            Province = province;
            Zip = zip;
            Street = street;
        }

        public string Province { get; private set; }
        public string Street { get; private set; }
        public string Zip { get; private set; }


        #region "equals"
        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        public override bool Equals(Address other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Equals(other.Province, Province) && Equals(other.Street, Street) && Equals(other.Zip, Zip);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = (Province != null ? Province.GetHashCode() : 0);
                result = (result * 397) ^ (Street != null ? Street.GetHashCode() : 0);
                result = (result * 397) ^ (Zip != null ? Zip.GetHashCode() : 0);
                return result;
            }
        }

        public static bool operator ==(Address left, Address right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(Address left, Address right)
        {
            return !Equals(left, right);
        } 
        #endregion
    }
}
